<template>
  <div>
    <van-sticky>
      <van-nav-bar
        title="确认订单"
        left-arrow
        @click-left="onClickLeft(id)"
        fixed
      />
    </van-sticky>
    <van-address-edit
      :show-area="false"
      show-postal
      show-delete
      show-set-default
      show-search-result
      @save="onSave"
      @delete="onDelete"
    />
  </div>
</template>

<script>
export default {
  name: "Addressedit",

  data() {
    return {
      id: this.$route.params.id,
      name: "",
      tel: "",
      addressDetail: "",
      areaCode: "",
      area:[],
    };
  },

  mounted() {
    this.getAddress(this.id)
  },

  methods: {
    getAddress(id){
      this.$axios.get('/address/' + id).then(res => {
        this.area = res.data
        console.log(res.data);
      })
    },
    onClickLeft(id) {
      this.$router.push("/editList/" + id);
    },
    onSave(value) {
      let data = {
        name: value.name,
        tel: value.tel,
        address: value.addressDetail,
        postalCode: value.postalCode,
      };
      
      this.$axios.post("/address", data).then((res) => {
        if (res.statusText == "Created") {
          this.$dialog.alert({
            title: "提示",
            message: "添加成功",
          });
        }
      });
    },
    onDelete() {
      Toast("delete");
    },
  },
};
</script>

<style scoped>
.van-address-edit {
  margin-top: 40px;
}
</style>